 var Event = (function () {
 	var _default = 'default';

 	var each = function (ary, fn) {
 		for (var i = 0; i < ary.length; i++) {
 			fn.call(ary[i], ary[i], i)
 		}
 	}
 	var Event = (function () {
 		var _listen,
 			_tirgger,
 			_remove,
 			_create,
 			_unshift,
 			_shift,
 			_pop,
 			_push,
 			cache,
 			offlineStack,
 			Event;
 		var nameSpaceBox = {};
 		_unshift = Array.prototype.unshift;
 		_shift = Array.prototype.shift;
 		_pop = Array.prototype.pop;
 		_push = Array.prototype.push;
 		_listen = function (key, fn, cache) {
 			if (!cache[key]) cache[key] = [];
 			cache[key].push(fn);
 		}
 		_tirgger = function () {
 			var key = _shift.call(arguments);
 			var cache = _pop.call(arguments);
 			var args = arguments;
 			var self = this;
 			if (!cache[key] || !cache[key].length) return false;
 			each(cache[key], function () {
 				this.apply(self, args);
 			})
 		}
 		_remove = function (key, cache, fn) {
 			if (!cache[key]) return false;
 			if (!fn) {
 				cache[key].length = 0;
 			} else {
 				for (var i = cache[key].length; i >= 0; i--) {
 					var _fn = cache[key][i]
 					if (_fn == fn) {
 						cache[key].splice(i, 1);
 					}
 				}
 			}

 		}

 		_create = function (namespace) {
 			var cache = {};
 			var offlineStack = [];
 			var namespace = namespace || _default;
 			var ret = {
 				one: function (key, fn, last) {
 					_remove(key, cache);
 					this.listen(key, fn, last);
 				},
 				listen: function (key, fn, last) {
 					_listen(key, fn, cache);
 					if (!offlineStack) return false;
 					if (last == 'last') {
 						offlineStack.length && offlineStack.pop()();
 					} else {
 						each(offlineStack, function () {
 							this();
 						})
 					}
 					offlineStack = null;
 				},
 				remove: function (key, fn) {
 					_remove(key, cache, fn);
 				},
 				tirgger: function () {

 					_push.call(arguments, cache);
 					var _self = this;
 					var args = arguments;
 					var fn = function () {
 						return _tirgger.apply(_self, args);
 					}
 					if (offlineStack) {
 						return offlineStack.push(fn);
 					}
 					fn();
 				}
 			}
 			return namespace ? (nameSpaceBox[namespace] ? nameSpaceBox[namespace] : nameSpaceBox[namespace] = ret) : ret;

 		}
 		return {
 			create: _create,
 			one: function (key, fn, last) {
 				var event = this.create();
 				event.one(key, fn, last);
 			},
 			listen: function (key, fn, last) {
 				var event = this.create();
 				event.listen(key, fn, last);
 			},
 			remove: function (key, fn) {
 				var event = this.create();
 				event.remove(key, fn)
 			},
 			tirgger: function () {
 				var event = this.create();
 				event.tirgger.apply(this, arguments)
 			}
 		}
 	})()
 	return Event;
 })()



 if (typeof define == 'function') {

 	define([], function () {
 		return {
 			Event: Event
 		}
 	})
 }